define(['text!T_UITabView','m_zepto'],function(T_UITabView) {
  'use strict';
  var Tab =function(ele,opt){
    this.$element = ele,
    this.defaults = {
        'pageName':['p_view_home','p_view_funds','p_view_wealth','p_view_more'],
        'curIndex':0,
        'hasLabel':true,
        'hasAnim':true,
        data:null,
        callback:null,
        clickFunc:null
    },
    this.options = $.extend({}, this.defaults, opt)
    this.init = function(){
        var self=this;
        var tab_tmp= _.template(T_UITabView);
        self.$element.html(tab_tmp({curIndex:self.options.curIndex,data:self.options.data,pageName:self.options.pageName}));
        self.$element.find('a').on('click',function(){
          self.itemClick($(this).data('view'));
        });
    }
  };

  Tab.prototype = {
    itemClick : function(index) { //切换窗口显示
      $('.tab-actived').removeClass('tab-actived');
      $('[data-view="'+index+'"]').addClass('tab-actived');
      
     var self = this;     
      this.show(index);
      sessionStorage.setItem("indexHash",self.defaults.pageName[index]); 

      if(self.defaults.pageName[index] == 'p_view_funds' ||  self.defaults.pageName[index] == 'p_view_wealth'){
          var e = document.getElementsByTagName("header")[0].getElementsByTagName("style")[0];
        e.innerHTML = 'header{display: -webkit-box !important;display: box !important;}#wrapper{padding-top:2.5em;}#content{padding-top:2.5em;}';

      }else{
          isHideTitle();
      }
      
      var $next = $('.virtualPage[page="'+self.options.pageName[index]+'"]');
      $('.virtualTitle').css({display:'none !important'});
       $('.virtualTitle[page="'+self.defaults.pageName[index]+'"]').css({display:''});
       
         // if(self.defaults.pageName[index] == 'p_view_home'){
              // piwikTrackEvent(Piwik_Event_Quota.index.category,Piwik_Event_Quota.index.index.action,"");
         // }else  if(self.defaults.pageName[index] == 'p_view_funds'){
              // piwikTrackEvent(Piwik_Event_Quota.index.category,Piwik_Event_Quota.index.product.action,"");
         // }else  if(self.defaults.pageName[index] == 'p_view_wealth'){
              // piwikTrackEvent(Piwik_Event_Quota.index.category,Piwik_Event_Quota.index.wealth.action,"");
         // }else{
             // piwikTrackEvent(Piwik_Event_Quota.index.category,Piwik_Event_Quota.index.more.action,"");
         // }
        if(this.options.clickFunc && typeof(this.options.clickFunc=="function")) this.options.clickFunc();
    },
    show:function(next,callback){
      var self = this;
      var $next = $('.virtualPage[page="'+self.options.pageName[next]+'"]');
      $('.virtualPage').css({display:'none !important'});
      if(!$next.length){
        self.options.callback(self.options.pageName[next]);
        return;
      }
      $('.virtualPage[page="'+self.defaults.pageName[next]+'"]').css({display:'block !important'});
      self.options.curIndex = next;
      setTimeout(function(){
        $(window).scrollTop(0);
      },200)
    }
  }

  $.fn.tab = function(opt){
    var tab = new Tab(this,opt);
    return tab.init(),tab
  }
});

